﻿@model IndoReputation.Views.ViewModels.CountryViewModel
@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section _Right {
    @Html.Partial("_Right")
}
<h2>
    Add</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <div class="form-data">
            <table class="table-data">
                <tr>
                    <td class="td-label">
                        <div class="editor-label">
                            @Html.LabelFor(model => model.Region)
                        </div>
                    </td>
                    <td class="td-control">
                        <div class="editor-field">
                            @Html.DropDownListFor(x => x.RegionID, new SelectList(Model.Region, "Value", "Text"), "-- Select Region --")
                            @Html.ValidationMessageFor(model => model.RegionID)
                        </div>
                    </td>
                </tr>
            <!--
                <tr>
                    <td class="td-label">
                        <div class="editor-label">
                            @Html.LabelFor(model => model.Organization)
                        </div>
                    </td>
                    <td class="td-control">
                        <div class="editor-field">
                            @Html.DropDownListFor(x => x.OrganizationID, new SelectList(Model.Organization, "Value", "Text"), "-- Select Organization --")
                            @Html.ValidationMessageFor(model => model.OrganizationID)
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="td-label">
                        <div class="editor-label">
                            @Html.LabelFor(model => model.DialogPartner)
                        </div>
                    </td>
                    <td class="td-control">
                        <div class="editor-field">
                            @Html.DropDownListFor(x => x.DialogPartnerID, new SelectList(Model.DialogPartner, "Value", "Text"), "-- Select DialogPartner --")
                            @Html.ValidationMessageFor(model => model.DialogPartnerID)
                        </div>
                    </td>
                </tr>
                -->
                <tr>
                    <td class="td-label">
                        <div class="editor-label">
                            @Html.LabelFor(model => model.Name, null, true)
                        </div>
                    </td>
                    <td class="td-control">
                        <div class="editor-field">
                            @Html.EditorFor(model => model.Name)
                            @Html.ValidationMessageFor(model => model.Name)
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="td-label">
                        <div class="editor-label">
                            @Html.Label("", "Upload Flag. Maximum allowed file size: 100 KB")
                        </div>
                    </td>
                    <td class="td-control">
                        <div class="editor-field">
                            @(Html.Telerik().Upload()
                                .Name("attachments")
                                .Multiple(false)
                                .Async(async => async
                                .Save("Save", "Country")
                                .Remove("Remove", "Country")
                                .AutoUpload(true)
                                ).ClientEvents(e => e.OnUpload("onUpload"))
                             )
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <p class="dvbutton">
                            <input type="submit" value="Create" />
                        </p>
                    </td>
                </tr>
            </table>
        </div>
    </fieldset>        
}
<div class="div-back">
    @Html.ActionLink("Back to List", "Index")
</div>
<script type="text/javascript" language="javascript">
    function onUpload(e) {
        // Array with information about the uploaded files
        var files = e.files;
        var bytesPerMB = 1048576;
        // Check the extension of each file and abort the upload if it is not .jpg
        $.each(files, function () {
            if (this.size && (this.size > bytesPerMB / 10)) {
                alert("Your image is greater than 100 KB in size. Please select a smaller image")
                e.preventDefault();
                return false;
            }
            if (this.extension != ".jpg" && this.extension != ".png" && this.extension != ".gif") {
                alert("Only *.jpg, *.png, *.gif files can be uploaded")
                e.preventDefault();
                return false;
            }
        });
    }
</script>